﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Dev01.BussinessObject;

namespace Dev01.DataAccsess
{
    class GoodsData
    {
        DataService D_MS = new DataService();

        public DataTable Load()
        {
            string sql = "select* from tblGoods";
            SqlCommand cmd = new SqlCommand(sql);
            D_MS.Load(cmd);
            return this.D_MS;
        }

        public bool Them(GoodsInfo g)
        {
            string sql = "insert into tblGoods(HH_MA,HH_TEN,HH_NGAYNHAP,HH_SOLUONG,HH_GIANHAP,HH_GIABAN,NV_MA,HH_TINHTRANG,HH_GHICHU) "
                        + "values('" + g.Ma + "','" + g.Ten + "','" + g.NgayNhap + "'," + g.SoLuong + "," + g.GiaNhap + "," + g.GiaBan + ",'" + g.MaNV + "'," + g.TinhTrang + ",'" + g.GhiChu + "')";
            SqlCommand cmd = new SqlCommand(sql);
            if (D_MS.ExecuteNoneQuery(cmd) > 0)
                return true;
            else
                return false;
        }

        public bool Sua(GoodsInfo g)
        {
            string sql = "update tblGoods set HH_TEN = '" + g.Ten + "',HH_NGAYNHAP = '" + g.NgayNhap + "',HH_SOLUONG = " + g.SoLuong + ",HH_GIANHAP = " + g.GiaNhap + ",HH_GIABAN = " + g.GiaBan + ", "
                        + "NV_MA = '" + g.MaNV + "',HH_TINHTRANG = " + g.TinhTrang + ",HH_GHICHU = '" + g.GhiChu + "' where HH_MA = '" + g.Ma + "'";
            SqlCommand cmd = new SqlCommand(sql);
            if (D_MS.ExecuteNoneQuery(cmd) > 0)
                return true;
            else
                return false;
        }

        public bool Xoa(string Ma)
        {
            string sql = "delete from tblGoods where HH_MA = '" + Ma + "'";
            SqlCommand cmd = new SqlCommand(sql);
            if (D_MS.ExecuteNoneQuery(cmd) > 0)
                return true;
            else
                return false;
        }
    }
}
